<?php

/* 定义配置信息 */

try{
    $WX_APPID='wxcc2981e77c6dcfda';
    $WX_SECRET='97839b3024f8a92be18f46f97f3f4abb';
    $code=empty($_GET['code'])?"":$_GET['code'];
    if($code==""){
        $re = '{"access_token":"ACCESS_TOKEN","expires_in":7200,  "refresh_token":"REFRESH_TOKEN","openid":"123456","scope":"SCOPE"}';
    }
    else{
        $re = file_get_contents('https://api.weixin.qq.com/sns/oauth2/access_token'."?appid=$WX_APPID&secret=$WX_SECRET&code=$code&grant_type=authorization_code");
    }
    $re = json_decode($re);
    if($re->errcode){
        $file = fopen("err_log.txt","w");
        fwrite($file,$re);
    }

    if($re->openid){
        setcookie('wxid',empty($re->openid)?"":$re->openid);

        $url=$_GET['upp'];
        $u="";
        if(empty($url)){
            $u="index.php";
        }else{
            if(strpos($url,'|')>0){
                $u=explode('|', $url);
                $u=$u[0]."&".$u[1];
            }else{
                $u=$url;
            }
        }
        header("Location: $u");
    }
}catch(Exception $e){
}




// https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxcc2981e77c6dcfda&redirect_uri=http%3A%2F%2Fdskc.csrsfwl.com%2Fweixin.php%3Fupp%3Dindex.php%253Fapp%253Dmenu&response_type=code&scope=snsapi_userinfo&state=#wechat_redirect